package com.tianji.promotion.service.impl;

import com.tianji.promotion.domain.po.CouponScope;
import com.tianji.promotion.mapper.CouponScopeMapper;
import com.tianji.promotion.service.ICouponScopeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 优惠券作用范围信息 服务实现类
 * </p>
 *
 * @author LYQ
 * @since 2024-07-03
 */
@Service
public class CouponScopeServiceImpl extends ServiceImpl<CouponScopeMapper, CouponScope> implements ICouponScopeService {

    /**
     * 删除对应优惠券Id的课程绑定关系表数据
     *
     * @param couponId
     */
    @Override
    public void removeByCouponId(Long couponId) {
        getBaseMapper().removeByCouponId(couponId);
    }

    /**
     * 查到对应couponId 的BizIds
     *
     * @param couponId
     */
    @Override
    public List<Long> getBizIdsByCouponId(Long couponId) {
        return lambdaQuery()
                .select(CouponScope::getBizId)
                .eq(CouponScope::getCouponId, couponId)
                .list().stream().map(CouponScope::getBizId).collect(Collectors.toList());
    }
}
